SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE dbo.DnnProduct_Dashboard_AddControl  

	@PackageId							int,
	@DashboardControlKey 				nvarchar(50),
	@IsEnabled							bit,
	@DashboardControlSrc				nvarchar(250),
	@DashboardControlLocalResources 	nvarchar(250),
	@ControllerClass					nvarchar(250),
	@ViewOrder							int

AS
	IF @ViewOrder = -1
		SET @ViewOrder = (SELECT TOP 1 ViewOrder FROM DnnProduct_Dashboard_Controls ORDER BY ViewOrder DESC) + 1

	INSERT INTO dbo.DnnProduct_Dashboard_Controls (
		PackageId,
		DashboardControlKey,
		IsEnabled,
		DashboardControlSrc,
		DashboardControlLocalResources,
		ControllerClass,
		ViewOrder
	)
	VALUES (
		@PackageId,
		@DashboardControlKey,
		@IsEnabled,
		@DashboardControlSrc,
		@DashboardControlLocalResources,
		@ControllerClass,
		@ViewOrder
	)

	SELECT SCOPE_IDENTITY()
    
GO
